#include <cstdlib>
#include <sstream>
#include <osg/io_utils>
#include <osg/Geode>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <osgDB/ReadFile>
#include <osg/Node>
#include <osg/Image>


osg::Camera* createOrthoCamera(double width, double height)
{
	osg::Camera* camera = new osg::Camera();

	camera->getOrCreateStateSet()->setMode(
		GL_LIGHTING,
		osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF
	);

	osg::Matrix m = osg::Matrix::ortho2D(0.0f, width, 0.0f, height);

	camera->setProjectionMatrix(m);
	camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
	camera->setViewMatrix(osg::Matrix::identity());
	camera->setClearMask(GL_DEPTH_BUFFER_BIT);
	camera->setRenderOrder(osg::Camera::POST_RENDER);

	return camera;
}



typedef std::list<unsigned int> Sizes;


int main(int argc, char** argv)
{
	osgViewer::Viewer   viewer;
	
	viewer.addEventHandler(new osgViewer::StatsHandler());
	viewer.addEventHandler(new osgViewer::WindowSizeHandler());

	osg::Group*  group  = new osg::Group();
	osg::Camera* camera = createOrthoCamera(1280.0f, 1024.0f);

	osg::Node* cube = osgDB::readNodeFile("../data/mesh/3dstest.osg");

	group->addChild(camera);
	group->addChild(cube);
	viewer.setSceneData(group);
	return viewer.run();
}

